import instance  from "../utils/request";

export async function createTravelPlan(travelPlan){
    try {
        const res = await instance({
            url: '/TravelPlan/create',
            method: 'post',
            data: travelPlan
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function updateTravelPlan(planId, travelPlan){
    try {
        const res = await instance({
            url: '/TravelPlan/update',
            method: 'put',
            params: {
                planId: planId
            },
            data: travelPlan
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function deleteTravelPlan(planId){
    try {
        const res = await instance({
            url: `/TravelPlan/delete/${planId}`,
            method: 'delete',
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getTravelPlanByPlanId(planId){
    try {
        const res = await instance({
            url: `/TravelPlan/detail/${planId}`,
            method: 'get',
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}

export async function getTravelPlanByUserId(userId, pageNumber, pageSize){
    try {
        const res = await instance({
            url: `/TravelPlan/user/${userId}`,
            method: 'get',
            params: {
                pageNumber: pageNumber,
                pageSize: pageSize
            }
        });
        return res;
    } catch (err) {
        console.log(err);
    }
}